package com.yangyang.lamviarm.server.entity;

import java.util.ArrayList;
import java.util.List;

public abstract class JEntity {

	protected int mPosition; // �����λ��(��ά��꣬����λ��ʾx��ǰ��λ��ʾy)
	private List<String> mProperty; // ���������
	private int mExtraPro; // ����ĸ�������(�������Բ�ͬ�������в�ͬ�ĺ���)
	private String mName; // ���������
	private String mType; // ���������

	public int getPosition() {
		return mPosition;
	}

	public String getName() {
		return this.mName;
	}

	public List<String> getProperty() {
		return mProperty;
	}

	public int getExtraPro() {
		return mExtraPro;
	}

	// public JEntity() {
	// this("untyped", "unnamed", 0);
	// }

	public JEntity(String type, String name, int position) {
		this.mType = type;
		this.mName = name;
		this.mPosition = position;
		this.mProperty = new ArrayList<String>();
		this.mExtraPro = -1;
	}

	public boolean moveTo(int newposition) {
		int distance = Math.abs(newposition - this.mPosition);
		return newposition > 0 && this.mPosition > 0
				&& (distance == 1 || distance == 1000)
				&& (this.mPosition = newposition) > 0;
	}

	public void addProperty(String pro) {
		if (!this.mProperty.contains(pro))
			this.mProperty.add(pro);
	}

	public void removeProperty(String pro) {
		this.mProperty.remove(pro);
	}

	public String getType() {
		return this.mType;
	}

	@Override
	public String toString() {
		String msg = this.mName + "," + this.mPosition + "\n";
		for (String pro : this.mProperty)
			msg += pro + ",";
		return msg;
	}

	public abstract boolean doAction(String action, Object[] params);
}
